Intro
In the backtesting analysis, I have established several different profitable strategies for timing entry/exits. Visit the XRP page to see how these signals were identified.
Simple moving average (SMA)
Exponential moving average (EMA)
SMA crosses
EMA crosses
Directional movement index (DMI)
True strength index (TSI) BEST
Stochastic oscillator (stoch)
Double RSI
Donchian channel
Ensembl indicator
This script will examine the price action and these trade signals just before the daily close. If the signal is TRUE, it is bullish and if FALSE it is bearish. When there is a switch from bearish to bullish it is a buy signal and when it switches from bullish to bearish it is a sell signal. This HTML is updated just before the daily close each day, but push notifications for any trade signals are also sent by push bullet.
To receive these signals in real-time, subscribe to the following channels - it’s free for a limited time!
https://www.pushbullet.com/channel?tag=xrp_signal
If you need some help to design your own trading signals/strategies, I am happy to help for a fee. email me at mark.ziemann{αt}gmail.com for any enquiries/suggestions/feedback.
This report is distributed for FREE under the MIT licence, but if you find it useful, consider a small tip.
Reminder: this analysis is not financial advice.
suppressPackageStartupMessages({
library("jsonlite")
library("tidyverse")
library("runner")
library("quantmod")
library("TTR")
library("RPushbullet")
library("kableExtra")
})
TESTING = FALSE
MYNOTE = NULL
mydate <- Sys.time()
attr(mydate, "tzone") <- "UTC"
mydate <- as.Date(mydate)
Get XRP parameters
params <- read.table("https://mdz-analytics.com/coins/XRP/XRP_dat.txt", header=TRUE)
params %>% kbl(caption="optimised backtested parameters") %>% kable_styling("hover", full_width = F)
| indicator | parameter | meanROI | totalROI | ntrades | ndays | xhodl |
|---|---|---|---|---|---|---|
| SMA | 10 | 1.140780 | 37002.249 | 237 | 3320 | 665.4113 |
| EMA | 8 | 1.103363 | 19501.660 | 293 | 3320 | 350.6983 |
| SMAcross | 7,5 | 1.079556 | 9708.236 | 281 | 3320 | 174.5832 |
| EMAcross | 6,5 | 1.188120 | 17482.622 | 156 | 3320 | 314.3899 |
| DMI | 6 | 1.148268 | 5772.254 | 181 | 3320 | 103.8024 |
| DC | 5 | 1.162405 | 14421.631 | 177 | 3320 | 259.3441 |
| TSI | 12,8,18 | 1.235562 | 64959.594 | 119 | 3320 | 1168.1682 |
| stoch | 3,26,35 | 1.318013 | 95777.556 | 106 | 3320 | 1722.3675 |
| RSI2 | 40,42 | 1.151156 | 37766.863 | 165 | 3320 | 679.1614 |
| Ensemble | SMA,SMAcross,DMI,TSI,RSI2,4 | 1.178991 | 175331.157 | 172 | 3320 | 3174.9249 |
Get XRP price data
Obtaining XRP price data (daily) for the last 300 days and today’s price.
URL="https://web-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/historical?symbol=XRP&convert=USD&interval=daily&count=300"
download.file(URL,destfile="xrpdat.txt")
xrpdat <- fromJSON("xrpdat.txt")
price <- xrpdat$data$quotes
price <- data.frame( as.Date(price$time_close) , price$quote$USD$high, price$quote$USD$low, price$quote$USD$close)
colnames(price) <- c("date","high","low","close")
URL="https://web-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/historical?symbol=XRP&convert=USD&interval=hourly&time_period=hourly&count=11"
download.file(URL,destfile="xrpdat.txt")
xrpdat <- fromJSON("xrpdat.txt")
price2 <- xrpdat$data$quotes
price2 <- data.frame( as.Date(price2$time_close) , price2$quote$USD$high, price2$quote$USD$low, price2$quote$USD$close,stringsAsFactors=FALSE)
colnames(price2) <- c("date","high","low","close")
high <- max(price2[,2])
low <- min(price2[,3])
close <- price2[nrow(price2),4]
df <- data.frame(date=mydate,high=high,low=low,close=close,stringsAsFactors=FALSE)
price <- rbind(price,df)
tail(price) %>% kbl(row.names = FALSE) %>% kable_styling("hover", full_width = F)
| date | high | low | close |
|---|---|---|---|
| 2022-09-21 | 0.4283253 | 0.3880088 | 0.3968278 |
| 2022-09-22 | 0.4912289 | 0.3947854 | 0.4851006 |
| 2022-09-23 | 0.5522828 | 0.4589180 | 0.5071712 |
| 2022-09-24 | 0.5150153 | 0.4740187 | 0.4887162 |
| 2022-09-25 | 0.5183142 | 0.4787337 | 0.4926273 |
| 2022-09-26 | 0.4767679 | 0.4659060 | 0.4672788 |
if ( TESTING == TRUE) {
price[nrow(price),"Close"] <- price[nrow(price),"Close"] * 2
}
XRP SMA indicator
Now to determine whether XRP has crossed the SMA line.
price2 <- price
n <- as.numeric(params[params$indicator == "SMA",2])
price2$ma <- SMA(Cl(price2),n=n)
price2$signal <- price2$close > price2$ma
tail(price2) %>% kbl(row.names = FALSE) %>% kable_styling("hover", full_width = F)
| date | high | low | close | ma | signal |
|---|---|---|---|---|---|
| 2022-09-21 | 0.4283253 | 0.3880088 | 0.3968278 | 0.3652653 | TRUE |
| 2022-09-22 | 0.4912289 | 0.3947854 | 0.4851006 | 0.3778308 | TRUE |
| 2022-09-23 | 0.5522828 | 0.4589180 | 0.5071712 | 0.3951787 | TRUE |
| 2022-09-24 | 0.5150153 | 0.4740187 | 0.4887162 | 0.4098421 | TRUE |
| 2022-09-25 | 0.5183142 | 0.4787337 | 0.4926273 | 0.4264714 | TRUE |
| 2022-09-26 | 0.4767679 | 0.4659060 | 0.4672788 | 0.4375305 | TRUE |
today_signal <- price2[nrow(price2),"signal"]
previous_signal <- price2[(nrow(price2)-1),"signal"]
if (today_signal != previous_signal ) {
if ( (today_signal == TRUE ) & (previous_signal == FALSE ) ) {
xrp_signal="BUY"
}
if ( (today_signal == FALSE ) & (previous_signal == TRUE ) ) {
xrp_signal="SELL"
}
} else {
xrp_signal <- "NONE"
}
if (today_signal==TRUE) {
ens_SMA=TRUE
} else {
ens_SMA=FALSE
}
message(paste("XRP SMA signal:",xrp_signal))
## XRP SMA signal: NONE
plot(price2$close~as.Date(price2$date),type="l",
xlab="Date",ylab="price (USD)",main="XRP w SMA")
grid()
lines(price2$ma~ as.Date(price2$date) ,col="red")
if ( xrp_signal != "NONE") {
MYNOTE <- paste("The XRP SMA signal is", xrp_signal,".")
}
XRP EMA indicator
Now to determine whether XRP has crossed the EMA line.
price2 <- price
n <- as.numeric(params[params$indicator == "EMA",2])
price2$ma <- EMA(Cl(price2),n=n)
price2$signal <- price2$close > price2$ma
tail(price2) %>% kbl(row.names = FALSE) %>% kable_styling("hover", full_width = F)
| date | high | low | close | ma | signal |
|---|---|---|---|---|---|
| 2022-09-21 | 0.4283253 | 0.3880088 | 0.3968278 | 0.3780727 | TRUE |
| 2022-09-22 | 0.4912289 | 0.3947854 | 0.4851006 | 0.4018566 | TRUE |
| 2022-09-23 | 0.5522828 | 0.4589180 | 0.5071712 | 0.4252599 | TRUE |
| 2022-09-24 | 0.5150153 | 0.4740187 | 0.4887162 | 0.4393613 | TRUE |
| 2022-09-25 | 0.5183142 | 0.4787337 | 0.4926273 | 0.4511982 | TRUE |
| 2022-09-26 | 0.4767679 | 0.4659060 | 0.4672788 | 0.4547717 | TRUE |
today_signal <- price2[nrow(price2),"signal"]
previous_signal <- price2[(nrow(price2)-1),"signal"]
if (today_signal != previous_signal ) {
if ( (today_signal == TRUE ) & (previous_signal == FALSE ) ) {
xrp_signal="BUY"
}
if ( (today_signal == FALSE ) & (previous_signal == TRUE ) ) {
xrp_signal="SELL"
}
} else {
xrp_signal <- "NONE"
}
if (today_signal==TRUE) {
ens_EMA=TRUE
} else {
ens_EMA=FALSE
}
message(paste("XRP EMA signal:",xrp_signal))
## XRP EMA signal: NONE
plot(price2$close~as.Date(price2$date),type="l",
xlab="Date",ylab="price (USD)",main="XRP EMA")
grid()
lines(price2$ma~ as.Date(price2$date) ,col="red")
if ( xrp_signal != "NONE") {
MYNOTE <- paste("The XRP EMA signal is", xrp_signal,".")
}
XRP SMA cross indicator
The SMA cross is a reasonably good strategy.
price2 <- price
n <- as.numeric(unlist(strsplit(params[params$indicator == "SMAcross",2],",")))
n1 <- n[1]
n2 <- n[2]
price2$ma1 <- SMA(Cl(price2),n=n1)
price2$ma2 <- SMA(Cl(price2),n=n2)
price2$signal <- price2$ma2 > price2$ma1
tail(price2) %>% kbl(row.names = FALSE) %>% kable_styling("hover", full_width = F)
| date | high | low | close | ma1 | ma2 | signal |
|---|---|---|---|---|---|---|
| 2022-09-21 | 0.4283253 | 0.3880088 | 0.3968278 | 0.3739190 | 0.3868821 | TRUE |
| 2022-09-22 | 0.4912289 | 0.3947854 | 0.4851006 | 0.3965999 | 0.4085015 | TRUE |
| 2022-09-23 | 0.5522828 | 0.4589180 | 0.5071712 | 0.4180975 | 0.4382711 | TRUE |
| 2022-09-24 | 0.5150153 | 0.4740187 | 0.4887162 | 0.4340565 | 0.4585997 | TRUE |
| 2022-09-25 | 0.5183142 | 0.4787337 | 0.4926273 | 0.4532428 | 0.4740886 | TRUE |
| 2022-09-26 | 0.4767679 | 0.4659060 | 0.4672788 | 0.4647007 | 0.4881788 | TRUE |
today_signal <- price2[nrow(price2),"signal"]
previous_signal <- price2[(nrow(price2)-1),"signal"]
if (today_signal != previous_signal ) {
if ( (today_signal == TRUE ) & (previous_signal == FALSE ) ) {
xrp_signal="BUY"
}
if ( (today_signal == FALSE ) & (previous_signal == TRUE ) ) {
xrp_signal="SELL"
}
} else {
xrp_signal <- "NONE"
}
if (today_signal==TRUE) {
ens_SMAcross=TRUE
} else {
ens_SMAcross=FALSE
}
message(paste("XRP SMA cross signal:",xrp_signal))
## XRP SMA cross signal: NONE
plot(price2$close~as.Date(price2$date),type="l",
xlab="Date",ylab="price (USD)",main="XRP w SMA cross")
grid()
lines(price2$ma1~ as.Date(price2$date) ,col="red")
lines(price2$ma2~ as.Date(price2$date) ,col="blue")
if ( xrp_signal != "NONE") {
MYNOTE <- paste(MYNOTE, "The XRP SMA cross signal is", xrp_signal,".")
}
XRP EMA cross indicator
The EMA cross is a moderately profitable strategy.
price2 <- price
n <- as.numeric(unlist(strsplit(params[params$indicator == "EMAcross",2],",")))
n1 <- n[1]
n2 <- n[2]
price2$ma1 <- EMA(Cl(price2),n=n1)
price2$ma2 <- EMA(Cl(price2),n=n2)
price2$signal <- price2$ma2 > price2$ma1
tail(price2) %>% kbl(row.names = FALSE) %>% kable_styling("hover", full_width = F)
| date | high | low | close | ma1 | ma2 | signal |
|---|---|---|---|---|---|---|
| 2022-09-21 | 0.4283253 | 0.3880088 | 0.3968278 | 0.3839599 | 0.3875016 | TRUE |
| 2022-09-22 | 0.4912289 | 0.3947854 | 0.4851006 | 0.4128572 | 0.4200346 | TRUE |
| 2022-09-23 | 0.5522828 | 0.4589180 | 0.5071712 | 0.4398041 | 0.4490802 | TRUE |
| 2022-09-24 | 0.5150153 | 0.4740187 | 0.4887162 | 0.4537790 | 0.4622922 | TRUE |
| 2022-09-25 | 0.5183142 | 0.4787337 | 0.4926273 | 0.4648785 | 0.4724039 | TRUE |
| 2022-09-26 | 0.4767679 | 0.4659060 | 0.4672788 | 0.4655643 | 0.4706955 | TRUE |
today_signal <- price2[nrow(price2),"signal"]
previous_signal <- price2[(nrow(price2)-1),"signal"]
if (today_signal != previous_signal ) {
if ( (today_signal == TRUE ) & (previous_signal == FALSE ) ) {
xrp_signal="BUY"
}
if ( (today_signal == FALSE ) & (previous_signal == TRUE ) ) {
xrp_signal="SELL"
}
} else {
xrp_signal <- "NONE"
}
if (today_signal==TRUE) {
ens_EMAcross=TRUE
} else {
ens_EMAcross=FALSE
}
message(paste("XRP EMA cross signal is",xrp_signal))
## XRP EMA cross signal is NONE
plot(price2$close~as.Date(price2$date),type="l",
xlab="Date",ylab="price (USD)",main="XRP EMA cross")
grid()
lines(price2$ma1~ as.Date(price2$date) ,col="red")
lines(price2$ma2~ as.Date(price2$date) ,col="blue")
if ( xrp_signal != "NONE") {
MYNOTE <- paste(MYNOTE, "The XRP EMA cross signal is", xrp_signal,".")
}
XRP DMI indicator
Directional movement indicator is a good approach to identify trend changes.
n <- as.numeric(params[params$indicator == "DMI",2])
dmi.adx <- ADX(price[,c("high","low","close")],n=n)
price2 <- cbind(price,dmi.adx)
price2$signal <- dmi.adx[,1] > dmi.adx[,2]
tail(price2) %>% kbl(row.names = FALSE) %>% kable_styling("hover", full_width = F)
| date | high | low | close | DIp | DIn | DX | ADX | signal |
|---|---|---|---|---|---|---|---|---|
| 2022-09-21 | 0.4283253 | 0.3880088 | 0.3968278 | 31.72213 | 9.904333 | 52.41329 | 37.32119 | TRUE |
| 2022-09-22 | 0.4912289 | 0.3947854 | 0.4851006 | 44.15921 | 6.227413 | 75.28148 | 43.64790 | TRUE |
| 2022-09-23 | 0.5522828 | 0.4589180 | 0.5071712 | 50.55732 | 4.350968 | 84.15187 | 50.39857 | TRUE |
| 2022-09-24 | 0.5150153 | 0.4740187 | 0.4887162 | 43.63009 | 3.754810 | 84.15187 | 56.02412 | TRUE |
| 2022-09-25 | 0.5183142 | 0.4787337 | 0.4926273 | 38.79480 | 3.240420 | 84.58236 | 60.78382 | TRUE |
| 2022-09-26 | 0.4767679 | 0.4659060 | 0.4672788 | 34.91929 | 7.712358 | 63.81863 | 61.28962 | TRUE |
today_signal <- price2[nrow(price2),"signal"]
previous_signal <- price2[(nrow(price2)-1),"signal"]
if (today_signal != previous_signal ) {
if ( (today_signal == TRUE ) & (previous_signal == FALSE ) ) {
xrp_signal="BUY"
}
if ( (today_signal == FALSE ) & (previous_signal == TRUE ) ) {
xrp_signal="SELL"
}
} else {
xrp_signal <- "NONE"
}
if (today_signal==TRUE) {
ens_DMI=TRUE
} else {
ens_DMI=FALSE
}
message(paste("XRP DMI signal:",xrp_signal))
## XRP DMI signal: NONE
price2 <- as.data.frame(price2)
par(mfrow=c(2,1))
plot(price2$close~as.Date(price2$date),type="l",
xlab="Date",ylab="price (USD)",main="XRP USD price")
grid()
plot(price2$DIp~as.Date(price2$date),type="l", col="blue",
xlab="Date",ylab="price (USD)",main="XRP DMI")
grid()
lines(price2$DIn ~ as.Date(price2$date) ,col="red")
if ( xrp_signal != "NONE") {
MYNOTE <- paste(MYNOTE,"XRP DMI signal is", xrp_signal,".")
}
XRP TSI indicator
True Strength Indicator is one of the more profitable approaches. Its success lies in how it changes rapidly when momentum shifts. For most coins, this indicator performs “best” in backtesting analysis, which means it should carry relatively more weight than other indicators.
n <- as.numeric(unlist(strsplit(params[params$indicator == "TSI",2],",")))
n1 <- n[1]
n2 <- n[2]
ns <- n[3]
TSI <- function(x, n.first = 25, n.second = 13, n.signal = 7) {
#True Strength Indicator
#https://school.stockcharts.com/doku.php?id=technical_indicators:true_strength_index
x <- try.xts(x, error = as.matrix)
pc <- x - lag.xts(x, na.pad = T) #force lag.xts to get na padding
dspc <- EMA(EMA(pc, n = n.first), n = n.second)
dsapc <- EMA(EMA(abs(pc), n = n.first), n = n.second)
tsi <- 100 * (dspc/dsapc)
signal <- EMA(tsi, n = n.signal)
r <- cbind(tsi, signal)
r <- reclass(r, x)
if (!is.null(dim(r))) colnames(r) <- c("tsi", "signal")
return(r)
}
tsi <- TSI(price$close , n.first = n1, n.second = n2, n.signal = ns )
colnames(tsi) <- c("tsi","sig")
price2 <- cbind(price,tsi)
price2$signal <- tsi[,1] > tsi[,2]
tail(price2) %>% kbl(row.names = FALSE) %>% kable_styling("hover", full_width = F)
| date | high | low | close | tsi | sig | signal |
|---|---|---|---|---|---|---|
| 2022-09-21 | 0.4283253 | 0.3880088 | 0.3968278 | 27.79190 | 7.190603 | TRUE |
| 2022-09-22 | 0.4912289 | 0.3947854 | 0.4851006 | 39.58254 | 10.600280 | TRUE |
| 2022-09-23 | 0.5522828 | 0.4589180 | 0.5071712 | 47.49574 | 14.484013 | TRUE |
| 2022-09-24 | 0.5150153 | 0.4740187 | 0.4887162 | 47.54248 | 17.963852 | TRUE |
| 2022-09-25 | 0.5183142 | 0.4787337 | 0.4926273 | 47.88871 | 21.113837 | TRUE |
| 2022-09-26 | 0.4767679 | 0.4659060 | 0.4672788 | 42.38607 | 23.353019 | TRUE |
today_signal <- price2[nrow(price2),"signal"]
previous_signal <- price2[(nrow(price2)-1),"signal"]
if (today_signal != previous_signal ) {
if ( (today_signal == TRUE ) & (previous_signal == FALSE ) ) {
xrp_signal="BUY"
}
if ( (today_signal == FALSE ) & (previous_signal == TRUE ) ) {
xrp_signal="SELL"
}
} else {
xrp_signal <- "NONE"
}
if (today_signal==TRUE) {
ens_TSI=TRUE
} else {
ens_TSI=FALSE
}
message(paste("XRP TSI signal:",xrp_signal))
## XRP TSI signal: NONE
par(mfrow=c(2,1))
plot(price2$close ~ as.Date(price2$date),type="l",log="y",
xlab="Date",ylab="price (USD)",main="USD price")
grid()
plot(tsi[,1] ~ as.Date(price2$date),type="l",col="blue",
xlab="Date",ylab="TSI",main="TSI")
lines(as.Date(price2$date), tsi[,2] , col="red" )
grid()
par(mfrow=c(1,1))
if ( xrp_signal != "NONE") {
MYNOTE <- paste(MYNOTE,"XRP TSI signal is", xrp_signal,".")
}
XRP stochastic oscillator indicator
Similar to the TSI, the stoch can pinpoint early changes in momentum, however it may give many false positives.
n <- as.numeric(unlist(strsplit(params[params$indicator == "stoch",2],",")))
n1 <- n[1]
n2 <- n[2]
n3 <- n[3]
sto <- stoch(HLC(price), nFastK=n1 , nFastD=n2 , nSlowD=n2 , bounded = TRUE, smooth=n3)
price2 <- cbind(price,sto)
price2$signal <- price2$fastK > price2$fastD
tail(price2) %>% kbl(row.names = FALSE) %>% kable_styling("hover", full_width = F)
| date | high | low | close | fastK | fastD | slowD | signal |
|---|---|---|---|---|---|---|---|
| 2022-09-21 | 0.4283253 | 0.3880088 | 0.3968278 | 0.5424077 | 0.4469843 | 0.4685358 | TRUE |
| 2022-09-22 | 0.4912289 | 0.3947854 | 0.4851006 | 0.5897555 | 0.4526073 | 0.4658183 | TRUE |
| 2022-09-23 | 0.5522828 | 0.4589180 | 0.5071712 | 0.6310311 | 0.4605661 | 0.4635784 | TRUE |
| 2022-09-24 | 0.5150153 | 0.4740187 | 0.4887162 | 0.6452659 | 0.4684002 | 0.4617958 | TRUE |
| 2022-09-25 | 0.5183142 | 0.4787337 | 0.4926273 | 0.6358020 | 0.4756421 | 0.4604316 | TRUE |
| 2022-09-26 | 0.4767679 | 0.4659060 | 0.4672788 | 0.6134257 | 0.4826584 | 0.4595237 | TRUE |
today_signal <- price2[nrow(price2),"signal"]
previous_signal <- price2[(nrow(price2)-1),"signal"]
if (today_signal != previous_signal ) {
if ( (today_signal == TRUE ) & (previous_signal == FALSE ) ) {
xrp_signal="BUY"
}
if ( (today_signal == FALSE ) & (previous_signal == TRUE ) ) {
xrp_signal="SELL"
}
} else {
xrp_signal <- "NONE"
}
if (today_signal==TRUE) {
ens_stoch=TRUE
} else {
ens_stoch=FALSE
}
message(paste("XRP stoch signal:",xrp_signal))
## XRP stoch signal: NONE
par(mfrow=c(2,1))
plot(price2$close ~ as.Date(price2$date),type="l",log="y",
xlab="Date",ylab="price (USD)",main="USD price")
grid()
plot(price2$fastK ~ as.Date(price2$date),type="l",col="blue",
xlab="Date",ylab="index",main="stochastic oscillator")
lines(as.Date(price2$date), price2$fastD , col="red" )
grid()
par(mfrow=c(1,1))
if ( xrp_signal != "NONE") {
MYNOTE <- paste(MYNOTE,"XRP Stoch signal is", xrp_signal,".")
}
XRP double RSI indicator
Double RSI is simply two RSI lines.
n <- as.numeric(unlist(strsplit(params[params$indicator == "RSI2",2],",")))
n1 <- n[1]
n2 <- n[2]
rsi1 <- RSI(price$close,n=n1,maType=EMA)
rsi2 <- RSI(price$close,n=n2,maType=EMA)
price2 <- cbind(price,rsi1,rsi2)
price2$signal <- price2$rsi1 > price2$rsi2
tail(price2) %>% kbl(row.names = FALSE) %>% kable_styling("hover", full_width = F)
| date | high | low | close | rsi1 | rsi2 | signal |
|---|---|---|---|---|---|---|
| 2022-09-21 | 0.4283253 | 0.3880088 | 0.3968278 | 58.78873 | 58.48929 | TRUE |
| 2022-09-22 | 0.4912289 | 0.3947854 | 0.4851006 | 70.14906 | 69.64476 | TRUE |
| 2022-09-23 | 0.5522828 | 0.4589180 | 0.5071712 | 72.16584 | 71.64305 | TRUE |
| 2022-09-24 | 0.5150153 | 0.4740187 | 0.4887162 | 68.12013 | 67.73277 | TRUE |
| 2022-09-25 | 0.5183142 | 0.4787337 | 0.4926273 | 68.51340 | 68.11952 | TRUE |
| 2022-09-26 | 0.4767679 | 0.4659060 | 0.4672788 | 63.20117 | 62.98780 | TRUE |
today_signal <- price2[nrow(price2),"signal"]
previous_signal <- price2[(nrow(price2)-1),"signal"]
if (today_signal != previous_signal ) {
if ( (today_signal == TRUE ) & (previous_signal == FALSE ) ) {
xrp_signal="BUY"
}
if ( (today_signal == FALSE ) & (previous_signal == TRUE ) ) {
xrp_signal="SELL"
}
} else {
xrp_signal <- "NONE"
}
if (today_signal==TRUE) {
ens_RSI2=TRUE
} else {
ens_RSI2=FALSE
}
message(paste("XRP RSI signal:",xrp_signal))
## XRP RSI signal: NONE
par(mfrow=c(2,1))
plot(price2$close ~ as.Date(price2$date),type="l",log="y",
xlab="Date",ylab="price (USD)",main="USD price")
grid()
plot(price2$rsi1 ~ as.Date(price2$date),type="l",col="blue",
xlab="Date",ylab="index",main="double RSI")
lines(as.Date(price2$date), price2$rsi2 , col="red" )
grid()
par(mfrow=c(2,1))
plot(price2$close ~ as.Date(price2$date),type="l",log="y",
xlab="Date",ylab="price (USD)",main="USD price")
grid()
plot(price2$rsi1/price2$rsi2 ~ as.Date(price2$date),type="l",
xlab="Date",ylab="RSI ratio",main="double RSI")
grid()
abline(h=1,lty=2,lwd=2)
par(mfrow=c(1,1))
if ( xrp_signal != "NONE") {
MYNOTE <- paste(MYNOTE,"XRP RSI2 signal is", xrp_signal,".")
}
XRP Donchian channel indicator
n <- as.numeric(params[params$indicator == "DC",2])
price2 <- price[1:nrow(price)-1,]
dc <- DonchianChannel(price2$close,n=n)
price2$higher <- c(NA,sapply(2:nrow(dc),function(i) {
dc[i,"high"] > dc[(i-1),"high"]
} ))
price2$lower <- c(NA,sapply(2:nrow(dc),function(i) {
dc[i,"low"] < dc[(i-1),"low"]
} ))
price2 <- price2[price2$higher != price2$lower,]
# show changing rows only
price2 <- price2[c(NA,unlist(lapply(2:nrow(price2) , function(i) {
price2$higher[i] != price2$higher[i-1]
}))),]
price2 <- price2[!is.na(price2$higher),]
previous_signal <- price2[nrow(price2),"higher"]
price2 <- price
dc <- DonchianChannel(price2$close,n=n)
colnames(dc) <- c("dchigh","dcmid","dclow")
price2 <- cbind(price2,dc)
tail(price2) %>% kbl(row.names = FALSE) %>% kable_styling("hover", full_width = F)
| date | high | low | close | dchigh | dcmid | dclow |
|---|---|---|---|---|---|---|
| 2022-09-21 | 0.4283253 | 0.3880088 | 0.3968278 | 0.4151828 | 0.3867530 | 0.3583232 |
| 2022-09-22 | 0.4912289 | 0.3947854 | 0.4851006 | 0.4851006 | 0.4217119 | 0.3583232 |
| 2022-09-23 | 0.5522828 | 0.4589180 | 0.5071712 | 0.5071712 | 0.4471222 | 0.3870733 |
| 2022-09-24 | 0.5150153 | 0.4740187 | 0.4887162 | 0.5071712 | 0.4519995 | 0.3968278 |
| 2022-09-25 | 0.5183142 | 0.4787337 | 0.4926273 | 0.5071712 | 0.4519995 | 0.3968278 |
| 2022-09-26 | 0.4767679 | 0.4659060 | 0.4672788 | 0.5071712 | 0.4872250 | 0.4672788 |
xrp_signal="NONE"
# if we in negative territory, check whether time to buy
if ( previous_signal == FALSE ) {
if ( price2[nrow(price2),"dchigh"] > price2[nrow(price2)-1,"dchigh"] ) {
xrp_signal="BUY"
}
}
# if we in positive territory, check whether time to sell
if ( previous_signal == TRUE ) {
if ( price2[nrow(price2),"dclow"] < price2[nrow(price2)-1,"dclow"] ) {
xrp_signal="SELL"
}
}
if ( xrp_signal=="NONE" ) {
today_signal=previous_signal
} else {
if (xrp_signal=="BUY") { today_signal = TRUE }
if (xrp_signal=="SELL") { today_signal = FALSE }
}
if (today_signal==TRUE) {
ens_DC=TRUE
} else {
ens_DC=FALSE
}
message(paste("XRP DC signal:",xrp_signal))
## XRP DC signal: NONE
plot(price2$close ~ as.Date(price2$date),type="l",log="y",
xlab="Date",ylab="price (USD)",main="USD price",lwd=2)
grid()
lines(price2$dclow~ as.Date(price2$date),lwd=1.5,col="red")
lines(price2$dchigh~ as.Date(price2$date),lwd=1.5,col="limegreen")
price2 <- tail(price2,100)
plot(price2$close ~ as.Date(price2$date),type="l",log="y",
xlab="Date",ylab="price (USD)",main="USD price",lwd=2)
grid()
lines(price2$dclow~ as.Date(price2$date),lwd=1.5,col="red")
lines(price2$dcmid~ as.Date(price2$date),lwd=1.5,col="gray")
lines(price2$dchigh~ as.Date(price2$date),lwd=1.5,col="limegreen")
if ( xrp_signal != "NONE") {
MYNOTE <- paste(MYNOTE,"XRP Donchian channel signal is", xrp_signal,".")
}
XRP Ensemble indicator
This is a combination of a number of indicators.
ens <- params[params$indicator=="Ensemble","parameter"]
myrev <- intToUtf8(rev(utf8ToInt(ens)))
myrev <- unlist(strsplit(myrev,","))
# get thresh
n <- as.numeric(myrev[1])
myrev <- myrev[2:length(myrev)]
# get combination
combo <- sapply(myrev,function(s) { intToUtf8(rev(utf8ToInt(s))) })
message(paste("The combination is",paste(combo,collapse=" ")))
## The combination is RSI2 TSI DMI SMAcross SMA
message(paste("The buy threshold is",n))
## The buy threshold is 4
indicators <- c("SMA"=ens_SMA,
"EMA"=ens_EMA,
"SMAcross"=ens_SMAcross,
"EMAcross"=ens_EMAcross,
"DMI"=ens_DMI,
"TSI"=ens_TSI,
"stoch"=ens_stoch,
"RSI2"=ens_RSI2,
"DC"=ens_DC)
indicators <- indicators[names(indicators) %in% combo]
message("State of the indicators:")
## State of the indicators:
indicators
## SMA SMAcross DMI TSI RSI2
## TRUE TRUE TRUE TRUE TRUE
today_count <- sum(indicators)
message(paste("today_count_XRP",today_count,sep="="))
## today_count_XRP=5
today_signal <- today_count>=n
prev_html <- readLines("https://mdz-analytics.com/coins/XRP/alerts_XRP.html")
prev_signal <- length(grep("XRP ensemble indicator is BULLISH",prev_html))>2
xrp_signal <- "NONE"
if ( today_signal != prev_signal ) {
if ( today_signal == TRUE ) {
xrp_signal="BUY"
} else {
xrp_signal="SELL"
}
}
if (today_signal==TRUE) {
message("XRP ensemble indicator is BULLISH")
} else {
message("XRP ensemble indicator is BEARISH")
}
## XRP ensemble indicator is BULLISH
message(paste("XRP ENS signal:",xrp_signal))
## XRP ENS signal: NONE
if ( xrp_signal != "NONE") {
MYNOTE <- paste(MYNOTE,"XRP Ensemble indicator is", xrp_signal,".")
}
Send a push notification.
MYNOTE
## NULL
if ( !is.null(MYNOTE) ) {
MYNOTE <- paste(MYNOTE, ". Visit https://mdz-analytics.com/coins/XRP/alerts_XRP.html for the details")
MYNOTE
pbPost("note", "Crypto Alert", MYNOTE ,channel="xrp_signal")
}
Session information
For reproducibility
Click HERE to show session info
sessionInfo()
## R version 4.1.2 (2021-11-01)
## Platform: aarch64-unknown-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.1 LTS
##
## Matrix products: default
## BLAS: /usr/lib/aarch64-linux-gnu/blas/libblas.so.3.10.0
## LAPACK: /usr/lib/aarch64-linux-gnu/lapack/liblapack.so.3.10.0
##
## locale:
## [1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_AU.UTF-8 LC_COLLATE=en_AU.UTF-8
## [5] LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8
## [7] LC_PAPER=en_AU.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] kableExtra_1.3.4 RPushbullet_0.3.4 quantmod_0.4.20 TTR_0.24.3
## [5] xts_0.12.1 zoo_1.8-10 runner_0.4.1 forcats_0.5.1
## [9] stringr_1.4.0 dplyr_1.0.9 purrr_0.3.4 readr_2.1.2
## [13] tidyr_1.2.0 tibble_3.1.8 ggplot2_3.3.6 tidyverse_1.3.2
## [17] jsonlite_1.8.0
##
## loaded via a namespace (and not attached):
## [1] httr_1.4.4 sass_0.4.2 viridisLite_0.4.0
## [4] modelr_0.1.8 bslib_0.4.0 assertthat_0.2.1
## [7] highr_0.9 googlesheets4_1.0.1 cellranger_1.1.0
## [10] yaml_2.3.5 pillar_1.8.0 backports_1.4.1
## [13] lattice_0.20-45 glue_1.6.2 digest_0.6.29
## [16] rvest_1.0.2 colorspace_2.0-3 htmltools_0.5.3
## [19] pkgconfig_2.0.3 broom_1.0.0 haven_2.5.0
## [22] bookdown_0.28 scales_1.2.0 webshot_0.5.3
## [25] svglite_2.1.0 tzdb_0.3.0 googledrive_2.0.0
## [28] generics_0.1.3 ellipsis_0.3.2 cachem_1.0.6
## [31] withr_2.5.0 cli_3.3.0 magrittr_2.0.3
## [34] crayon_1.5.1 readxl_1.4.1 evaluate_0.16
## [37] fs_1.5.2 fansi_1.0.3 xml2_1.3.3
## [40] tools_4.1.2 hms_1.1.1 gargle_1.2.0
## [43] lifecycle_1.0.1 munsell_0.5.0 reprex_2.0.2
## [46] compiler_4.1.2 jquerylib_0.1.4 systemfonts_1.0.4
## [49] rlang_1.0.4 grid_4.1.2 rstudioapi_0.13
## [52] rmarkdown_2.15 gtable_0.3.0 DBI_1.1.3
## [55] curl_4.3.2 R6_2.5.1 lubridate_1.8.0
## [58] knitr_1.39 fastmap_1.1.0 utf8_1.2.2
## [61] stringi_1.7.8 parallel_4.1.2 rmdformats_1.0.4
## [64] Rcpp_1.0.9 vctrs_0.4.1 dbplyr_2.2.1
## [67] tidyselect_1.1.2 xfun_0.32